#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <cstrCmd.h>
#include <logbase.h>
int myChkCmdHello(void *cmdData, void *usrData)
{
    logdebugc("hello:%s", (const char *)cmdData);
    return 1;
}
int myChkCmdHelp(void *cmdData, void *usrData)
{
    cStrCmdMgrStc *tmpMgr = (cStrCmdMgrStc *)usrData;
    cStrCmdMgrPrtCmd(tmpMgr);
    return 1;
}
int myChkCmdExit(void *cmdData, void *usrData)
{
    logdebugc("do exit");
    exit(-1);
    return 1;
}
int myChkCmdAdd(void *cmdData, void *usrData)
{
    int a, b;
    if (!cmdData)
    {
        logerrorc("");
        return -1;
    }
    int tmplen = sscanf((const char *)cmdData, "%d %d", &a, &b);
    logdebugc("input:[%s], get len:%d, val:%d+%d=%d", (const char *)cmdData, tmplen, a, b, a + b);
    return 1;
}

extern cStrCmdMgrStc myChkCmdMgr;
cStrCmdInfStc myChkCmdList[] = {
    {"hello", "hello check", myChkCmdHello, &myChkCmdMgr},
    {"help", "print support command list", myChkCmdHelp, &myChkCmdMgr},
    {"exit", "exit code", myChkCmdExit, &myChkCmdMgr},
    {"add", "check add function", myChkCmdAdd, &myChkCmdMgr},
};

cStrCmdMgrStc myChkCmdMgr;

int main(int argc, char **argv)
{
    cStrCmdMgrInit(&myChkCmdMgr, myChkCmdList, ARRAY_LEN(myChkCmdList), &myChkCmdMgr);
    cStrCmdMgrDoCmd(&myChkCmdMgr, "hello", "it's my honor!");
    cStrCmdMgrDoCmd(&myChkCmdMgr, "help", NULL);
    cStrCmdMgrDoCmd(&myChkCmdMgr, "add", "10 21");
    cStrCmdMgrDoCmd(&myChkCmdMgr, "exit", NULL);
    logdebugc("func ptr");
    return 0;
}